package org.example.seckillsample.serviceImpl;

import com.alibaba.fastjson.JSON;
import org.example.seckillsample.entity.Commodity;
import org.example.seckillsample.entity.Order;
import org.example.seckillsample.mapper.CommodityMapper;
import org.example.seckillsample.mapper.OrderMapper;
import org.example.seckillsample.service.MqService;
import org.example.seckillsample.sto.OrderDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class MqServiceImpl implements MqService {
    @Autowired
    CommodityMapper commodityMapper;
    @Autowired
    OrderMapper orderMapper;

    @Override
    public void receiveMessage(String message) {
        OrderDto orderDto = JSON.parseObject(message,OrderDto.class);
        System.out.println(orderDto);
        commodityMapper.reduceStock(orderDto.getCommodityId());
        orderMapper.insert(orderDto.getCommodityId(),orderDto.getMoney(),orderDto.getPhone());
    }
}
